<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>string realize</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
	<script type="text/javascript">
		/*
		 * String object length property is count according to Unicode
		 */
		function lenTest()
		{
			var str = "hello";
			var st = "你好";
			alert(str.length);				// 5
			alert(st.length);				// 2
		}
		/*
		 * indexOf() will return Integer number of String object some or other member
		 */
		function indexTest()
		{
			var str = "adklakakdteop";
			var index = str.indexOf("k");
			alert(index);
		}
		/*
		 * 保证用户输入一个有效的数字,使用了match(regExp)方法,判断是否匹配指定的正则表达式
		 */
		function matchTest()
		{
			var strIn = prompt("请输入一个数字:",0);
			while(!strIn.match(/\d+/))
			{
				strIn = prompt("请输入一个数字:",0);
			}
		}	
	</script>
  </head>
  	<script type="text/javascript">
  		function splitTest()
  		{
  			var st = new Array();
  			st = "a,b,c".split(",");
  			var str = "a,b,c".split(",");
  			alert(st.type+" "+str.type);
  			alert("a,b,c".split(","));
  		}
  		//  小写用 toLowerCase()
  		function upperTest()
  		{
  			var st = "akdklaDeO";
  			var ust = st.toUpperCase();
  			alert(ust);
  		}
  	</script>
  <body>
     <input type="button" onClick="lenTest()" value="String object length test">
     <input type="button" onClick="splitTest()" value="split method test">
     <input type="button" onClick="indexTest()" value="indexOf string test" >
     <input type="button" onClick="substitute()" value="替换String object" >
     <br>
     <div>
     	<input type="button" onClick="matchTest()" value="匹配Test">
     	<input type="button" onClick="upperTest()" value="大写测试">
     	
     </div>
    <script type="text/javascript">
    	function substitute()
    	{
    		var str = "aaaaa";
    		alert("replace one character");
    		var st = str.replace("a","b");
    		alert(st);
    		alert("replace all character");
    		// 使用正则表达式实现了替换全部实例
    		var sta = str.replace(/a/g,"b");	
    		alert(sta);
    	}
    </script>
  </body>
</html>
